#include <cstdlib>
#include <ctime>
#include <set>


inline
mat
aux_functions::convert2Arma(cv::Mat cvImage)
{
  
  running_stat<double> stats;
  
  mat armaImage(cvImage.rows, cvImage.cols);
  
  for (uword row = 0; row< cvImage.rows; row++)
  {
    for (uword col = 0; col< cvImage.cols; col++)
    {
      armaImage(row,col) =  cvImage.at<uchar> (row, col);
      stats(armaImage(row,col));
    }
  }
  //cout<< "Normalization:" << endl;
  //armaImage = (armaImage - stats.mean())/stats.stddev();
  
  
  return armaImage;
}


inline
mat
aux_functions::convert2Arma(cv::Mat cvImage, double rescal)
{
  resize(cvImage, cvImage, cv::Size( cvImage.cols/rescal,cvImage.rows/rescal) );
  //cout << "Actual size = ( " << armaImage.n_rows << " , " << armaImage.n_cols  << " )"<< endl;
  running_stat<double> stats;
  
  mat armaImage(cvImage.rows, cvImage.cols);
  
  for (uword row = 0; row< cvImage.rows; row++)
  {
    for (uword col = 0; col< cvImage.cols; col++)
    {
      armaImage(row,col) =  cvImage.at<uchar> (row, col);
      stats(armaImage(row,col));
    }
  }
  //cout<< "Normalization:" << endl;
  //armaImage = (armaImage - stats.mean())/stats.stddev();
  //cout << "Actual size = ( " << armaImage.n_rows << " , " << armaImage.n_cols  << " )"<< endl;
  
  /*if ( armaImage.n_rows != floor(ima_rows/rescal) || armaImage.n_cols != floor(ima_cols/rescal))  
   *  { *
   *  cout << "Check image size"  << endl;
   *  cout << "Actual size = ( " << armaImage.n_rows << " , " << armaImage.n_cols  << " )"<< endl;
}*/
  
  return armaImage;
}

inline
vec
aux_functions::rand_vector(int min, int max, int n) // Random int vector between  [min, max]. Vectr size = n
{
  vec vector(n);
  int i = 0;
  srand(time(NULL));
  min = 10; //example minimum
  max = 600; //example minimum
  std::set<int> unique_set;
  while(unique_set.size() < n)
  {
    unique_set.insert((rand() % (max - min)) + min);
  }
  for(std::set<int>::iterator it = unique_set.begin(); it != unique_set.end(); it++)
  {
    std::cout << *it << "  ";
    vector(i) = *it;
    i++;
  }
  vector.t().print("vector");
}
